/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entities.Exams;
import entities.Person;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author corneliugosa
 */
@Stateless
public class ExamsFacade extends AbstractFacade<Exams> implements ExamsFacadeLocal {
    @PersistenceContext(unitName = "School-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ExamsFacade() {
        super(Exams.class);
    }

    @Override
    public List<Exams> findByPerson(Person proffessor) {
        List<Exams> list = null;
        
        Query query = em.createNamedQuery("Exams.findByPerson");
        query.setParameter("proffessor", proffessor);
        list = query.getResultList();
        
        return list;
    }

    @Override
    public List<Exams> findByClass(entities.Class cls) {
        List<Exams> list = null;
        
        Query query = em.createNamedQuery("Exams.findByClass");
        query.setParameter("cls", cls);
        list = query.getResultList();
        
        return list;
    }

    @Override
    public Exams findById(Integer id) {
        Exams exam = null;
        
        Query query = em.createNamedQuery("Exams.findById");
        query.setParameter("id", id);
        exam = (Exams)query.getSingleResult();
        
        return exam;
    }

    @Override
    public List<Exams> findPending() {
        List<Exams> list = null;
        
        Query query = em.createNamedQuery("Exams.findPending");
        list = query.getResultList();
        
        return list;
    }
    
}
